#ifndef __GMM_
#define __GMM_

#include <opencv2/opencv.hpp>

using namespace std;


class GMM
{
public:
    static const int componentsCount = 5;

    GMM(cv::Mat &_model);
    double operator()(const cv::Vec3d color) const;
    double operator()(int ci, const cv::Vec3d color) const;
    int whichComponent(const cv::Vec3d color) const;

    void initLearning();
    void addSample(int ci, const cv::Vec3d color);
    void endLearning();

private:
    void calcInverseCovAndDeterm(int ci);
    cv::Mat model;
    double *coefs;
    double *mean;
    double *cov;

    //协方差的逆矩阵
    double inverseCovs[componentsCount][3][3];
    //协方差的行列式
    double covDeterms[componentsCount];

    double sums[componentsCount][3];
    double prods[componentsCount][3][3];
    int sampleCounts[componentsCount];
    int totalSampleCount;
};

#endif